/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sigmatrix.h5.dao.DisRebateConditionDao;
import com.sigmatrix.h5.dao.DisRebateStrategyDao;
import com.sigmatrix.h5.entity.DisRebateCondition;
import com.sigmatrix.h5.utils.CommonUtils;
import com.sigmatrix.sc.jdbc.common.dao.DaoImpl;

/**
 *@ClassName: DisRebateConditionDaoImpl
 *@Description: 触发条件
 *@author MH
 *@date 2017年8月17日 上午9:49:25
 */
@Repository
public class DisRebateConditionDaoImpl extends DaoImpl<DisRebateCondition,Integer> implements DisRebateConditionDao{
	
	@Autowired
	private DisRebateStrategyDao disRebateStrategyDao;
	
	@Override
	public DisRebateCondition findByStrategyId(Integer strategyId) {
		final StringBuffer sql = new StringBuffer();
		sql.append("select a.* from ");
		sql.append(disRebateStrategyDao.tableName()).append(" b,");
		sql.append(tableName()).append(" a ");
		sql.append(" where a._id = b._condition_id ");
		sql.append(" and b._id = ?");
		logger.info("sql="+sql.toString());
		logger.info("param="+strategyId);
		List<DisRebateCondition> list = jdbcTemplate.query(sql.toString(), new DefaultRowMapper(), strategyId);
		return CommonUtils.isEmpty(list)?null:list.get(0);
	}

}
